
package com.ksvip.next.components.sequence;

import javax.sql.DataSource;

import com.ksvip.next.components.sequence.properties.SingleSequenceConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter({DataSourceAutoConfiguration.class})
@EnableConfigurationProperties({SingleSequenceConfiguration.class})
public class SequenceGeneratorAutoConfigure {
    private final SingleSequenceConfiguration properties;
    private final DataSource dataSource;

    public SequenceGeneratorAutoConfigure(SingleSequenceConfiguration properties, DataSource dataSource) {
        this.properties = properties;
        this.dataSource = dataSource;
    }

    @Bean
    @Conditional({SingleSequenceCondition.class})
    public SequenceGenerator SingleSequenceGenerator() {
        return SequenceGeneratorFactory.createSingleSequenceGenerator(this.dataSource, this.properties);
    }
}
